import type { App } from 'leafer-ui'
import { Snap } from 'leafer-x-snap'

let snap: Snap | null = null

function createSnap(app: App) {
  snap = new Snap(app, {
    snapSize: 5,
    strokeWidth: 1,
    showLinePoints: false,
    isDash: true,
    dashPattern: [5],
  })

  return snap
}

export function startSnap(app: App) {
  const snap = createSnap(app)
  snap.enable(true)
}

export function stopSnap() {
  if (!snap)
    return

  snap.enable(false)
}
